can a dictionary type use get set c#

42

can a dictionary type use get set c# -

var test = new YourClass();
test["Item1"] = "Value1";

can a dictionary type use get set c# -

public class YourClass
{
    private readonly IDictionary<string, string> _yourDictionary = new Dictionary<string, string>();

    public string this[string key]
    {
        // returns value if exists
        get { return _yourDictionary[key]; }

        // updates if exists, adds if doesn't exist
        set { _yourDictionary[key] = value; }
    }
}

Comments

Submit
0 Comments